<template>
  <view class="video-card" @tap="navigateToVideo">
    <view class="thumbnail-container">
      <image :src="thumbnail" mode="aspectCover" class="thumbnail" />
      <view class="play-overlay">
        <view class="play-button" @tap.stop="navigateToVideo">
          <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="white"
            stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
            <polygon points="5 3 19 12 5 21 5 3"></polygon>
          </svg>
        </view>
      </view>
      <view class="duration-badge">{{ duration }}</view>
      <view v-if="isNew" class="new-badge">NEW</view>
    </view>

    <view class="card-content">
      <text class="title">{{ title }}</text>

      <view class="footer">
        <view class="instructor">
          <image :src="instructor.avatar" mode="aspectFill" class="instructor-avatar" />
          <text class="instructor-name">{{ instructor.name }}</text>
        </view>
        <view class="views">
          <svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 24 24" fill="none"
            stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
            <path d="M2 12s3-7 10-7 10 7 10 7-3 7-10 7-10-7-10-7Z"></path>
            <circle cx="12" cy="12" r="3"></circle>
          </svg>
          <text>{{ views }}次观看</text>
        </view>
      </view>
    </view>
  </view>
</template>

<script setup>
defineProps({
  title: {
    type: String,
    required: true
  },
  duration: {
    type: String,
    required: true
  },
  views: {
    type: String,
    required: true
  },
  thumbnail: {
    type: String,
    default: '/static/images/placeholder.png'
  },
  instructor: {
    type: Object,
    default: () => ({
      name: '',
      avatar: '/static/images/avatar.png'
    })
  },
  isNew: {
    type: Boolean,
    default: false
  }
});

// Function to navigate to the video page
const navigateToVideo = () => {
  uni.navigateTo({
    url: '/pages/video/video'
  });
};
</script>

<style scoped>
.video-card {
  border-radius: 12px;
  overflow: hidden;
  background-color: white;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
  transition: box-shadow 0.3s;
}

.video-card:active {
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.thumbnail-container {
  position: relative;
  height: 160px;
}

.thumbnail {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.play-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background-color: rgba(0, 0, 0, 0.2);
  opacity: 0;
  transition: opacity 0.3s;
}

.thumbnail-container:active .play-overlay {
  opacity: 1;
}

.play-button {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background-color: rgba(59, 130, 246, 0.8);
  backdrop-filter: blur(4px);
  color: white;
}

.duration-badge {
  position: absolute;
  bottom: 8px;
  right: 8px;
  padding: 2px 6px;
  border-radius: 4px;
  background-color: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  font-size: 12px;
  color: white;
}

.new-badge {
  position: absolute;
  top: 8px;
  left: 8px;
  padding: 2px 8px;
  border-radius: 9999px;
  background-color: #f43f5e;
  font-size: 12px;
  font-weight: 500;
  color: white;
}

.card-content {
  padding: 12px;
}

.title {
  font-size: 14px;
  font-weight: 500;
  color: #1f2937;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis;
}

.footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 8px;
}

.instructor {
  display: flex;
  align-items: center;
  gap: 8px;
}

.instructor-avatar {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  object-fit: cover;
}

.instructor-name {
  font-size: 12px;
  color: #4b5563;
}

.views {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  color: #6b7280;
}
</style>